package com.cqs.leetcode.bit;

import com.google.common.collect.Lists;

import java.util.List;

/**
 * @author lixqw
 * @date 2020/8/16
 */
public class IsUniqueLCCI {

    public boolean isUnique(String astr) {
        int result = 0;
        int len = astr.length();
        for (int idx = 0; idx < len; idx++) {
            char ch = astr.charAt(idx);
            int i = ch - 'a';
            //重复了
            if( ((result >> i ) & 1) == 1){
                return false;
            }
            result = result | (1<<i);
        }
        return true;
    }

    public static void main(String[] args) {
        IsUniqueLCCI isUniqueLCCI = new IsUniqueLCCI();

        List<String> tests = Lists.newArrayList("abcdea");

        for (String test : tests) {
            System.out.println(test + "\t" + isUniqueLCCI.isUnique(test));
        }
    }
}
